
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include "cJSON.h"
#include "JsonReader.h"
#include <iostream>
#include <string.h>
#include "JsonDataModel.h"

using namespace std;

/* Parse text to JSON, then render back to text, and print! */
void doit(char *text)
{
	char *out;cJSON *json;
	
	json=cJSON_Parse(text);
	if (!json) {printf("Error before: [%s]\n",cJSON_GetErrorPtr());}
	else
	{
		//out=cJSON_Print(json);
		//cJSON_Delete(json);
		//printf("%s\n",out);
		//free(out);
		cJSON* format = cJSON_GetObjectItem(json, "1");
		cJSON* format2 = cJSON_GetObjectItem(format, "settings"); 
		out = cJSON_Print(format2);
		printf("%s\n", out);
	}
}

/* Read a file, parse, render back, etc. */
void dofile(char *filename)
{
	FILE *f=fopen(filename,"rb");fseek(f,0,SEEK_END);long len=ftell(f);fseek(f,0,SEEK_SET);
	char *data=(char*)malloc(len+1);fread(data,1,len,f);fclose(f);
	doit(data);
	free(data);
}

int main (int argc, const char * argv[]) {

	//dofile("nj.json");
	//JsonReader reader("nj.json");
	//reader.getData("1 settings");
	//cout << "ok" << endl;
	//printf("%s\n", reader.getData("1 settings file_name"));
	vector<JsonDataModel> models = getJsonDataModelFromFile("../nj.json");
	cout << models[0].columns.code << endl;
	cout << models[0].service_marks[0].main.source << endl;	
	return 0;
}
